package cn.edu.java.thread.锁;

import lombok.SneakyThrows;

public class SynchronizedDemo {
    public static int count = 0;

    @SneakyThrows
    public static void main(String[] args) {
        Runnable runnable = new Runnable() {
            @Override
            public synchronized void run() {
                for (int i = 0; i < 1000; i++) {
                    count++;
                }
            }
        };

        new Thread(runnable).start();
        new Thread(runnable).start();

        Thread.sleep(1000);

        System.out.println("Count: " + count);  // Count: 2000
    }
}
